<template>
  <div class="product-card" @click="handleClick">
    <div class="product-image-placeholder"></div>
    <div class="product-details">
      <p class="product-title">{{ product.title }}</p>
      <span class="product-tag">{{ product.tag }}</span>
      <div class="product-pricing">
        <span class="product-price">
          ¥<strong>{{ product.price }}</strong>/天
        </span>
        <span class="product-period">{{ product.minRentalDays }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// 产品数据接口
interface Product {
  id: number;
  title: string;
  tag: string;
  price: string;
  minRentalDays: string;
}

// 定义组件的 props
const props = defineProps<{
  product: Product;
}>();

// 定义组件的 emits
const emit = defineEmits<{
  (e: 'click', product: Product): void;
}>();

// 处理产品卡片点击事件
const handleClick = () => {
  emit('click', props.product);
};
</script>

<style scoped lang="scss">
.product-card {
  width: 177px;
  height: 220px;
  box-sizing: border-box;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 5px;
  background-color: #fff;
  cursor: pointer;
  transition: transform 0.2s;

  &:active {
    transform: scale(0.98);
  }

  .product-image-placeholder {
    width: 100%;
    height: 140px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-image: url('@/assets/image/Bitmap@2x(1).webp');
  }

  .product-details {
    .product-title {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 16px;
      color: #333333;
      font-style: normal;
      margin-bottom: 3px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .product-tag {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 11px;
      color: #00C8BE;
      line-height: 16px;
      text-align: left;
      font-style: normal;
      background: #FFFFFF;
      border-radius: 3px;
      border: 1px solid #00C8BE;
      display: inline-block;
      padding: 0 4px;
    }
  }

  .product-pricing {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    line-height: 17px;
    font-style: normal;
    margin-top: 8px;

    .product-price {
      font-size: 15px;
      color: #F04F4F;
    }

    .product-period {
      font-size: 11px;
      color: #AAAAAA;
    }
  }
}
</style>